#include<iostream>
#include <vector> 
#include<algorithm>
using namespace std;

namespace test2 {
	bool binarySearch(const vector<int>& vec, int target) {
		if (vec.empty()) return false;

		auto low = vec.begin();
		auto high = vec.end() - 1;
		while (low < high) {
			auto mid = low + (high - low) / 2;
			if (*mid == target) return true;
			else if (*mid < target) low = mid + 1;
			else high = mid - 1;
		}
		return false;
	}

	int main5() {
		vector<int> vec = { 1, 9, 3, 4, 5, 6, 7, 8, 2, 10 };
		sort(vec.begin(), vec.end());
		cout << binarySearch(vec, 2) << endl;
		cout << binarySearch(vec, 5) << endl;
		cout << binarySearch(vec, 11) << endl;

		return 0;
	}
}